package com.example.stumanager.student;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.stumanager.R;
import com.example.stumanager.database.SurfTheInternetSql;
import com.example.stumanager.entity.SurfTheInternetEntity;

/**
 * 上网申请
 */
public class StudentSurfTheInternetPage extends AppCompatActivity {
    EditText t1,t2,t3 ;
    Button re;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.student_surf_the_internet_page);
        t1=findViewById(R.id.name);
        t2=findViewById(R.id.id);
        t3=findViewById(R.id.time);
        re = findViewById(R.id.re);
        re.setOnClickListener(view -> finish());
        Button submit=findViewById(R.id.submit);
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(t1.getText().toString().equals("") ||
                        t2.getText().toString().equals("") ||
                        t3.getText().toString().equals("")  ){
                    Toast.makeText(StudentSurfTheInternetPage.this, "不能为空", Toast.LENGTH_SHORT).show();
                    return ;
                }
                SurfTheInternetEntity f=new SurfTheInternetEntity(t1.getText().toString(),t2.getText().toString(),
                        t3.getText().toString() );
                SurfTheInternetSql db=new SurfTheInternetSql(getBaseContext());
                if(db.add(f)){
                    Toast.makeText(StudentSurfTheInternetPage.this, "添加成功", Toast.LENGTH_SHORT).show();

                }else{
                    Toast.makeText(StudentSurfTheInternetPage.this, "添加失败", Toast.LENGTH_SHORT).show();
                }

            }
        });

    }
}